<%@ Page Language="c#" MasterPageFile="~/SQLWebQuery.master" Title="SQL Web Query"
    Inherits="SqlWebAdmin.query" CodeFile="QueryDatabase.aspx.cs" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolKit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table>
        <tr>
            <td>
                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <tr>
                        <!--BEGIN ONE LINE-->
                        <td valign="bottom" colspan="2" height="8" width="100%">
                            <img src="images/spacer.gif" width="1" height="8" alt="" border="0" /></td>
                        <!--END ONE LINE-->
                    </tr>
                    <tr>
                        <!--BEGIN ONE LINE-->
                        <td align="left" width="12">
                            <img src="images/spacer.gif" width="12" height="1" alt="" border="0" /></td>
                        <!--END ONE LINE-->
                        <td align="left" class="databaseListItem" width="100%">
                            <!-- PAGE CONTENT: START -->
                            <!-- SECTION HEADER: START -->
                            <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                <tr>
                                    <td class="databaseListHeader">
                                        QUERY DATABASE
                                    </td>
                                </tr>
                                <!-- SECTION HEADER: END -->
                                <!-- SECTION: START -->
                                <tr>
                                    <!--BEGIN ONE LINE-->
                                    <td height="3" valign="middle" background="images/blue_dotted_line.gif">
                                        <img src="images/blue_dotted_line.gif" width="150" height="3" alt="" border="0" /></td>
                                    <!--END ONE LINE-->
                                </tr>
                                <tr>
                                    <!--BEGIN ONE LINE-->
                                    <td height="4" valign="middle">
                                        <img src="images/spacer.gif" width="1" height="4" alt="" border="0" /></td>
                                    <!--END ONE LINE-->
                                </tr>
                                <tr>
                                    <td bgcolor="white" class="databaseListItem">
                                        <table cellspacing="0" cellpadding="0" border="0" style="background-color: #f5f9ff;">
                                            <tr>
                                                <td colspan="2">
                                                    <ajaxToolKit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" />
                                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                        <ContentTemplate>
                                                            <div style="background-color: #d2e9fb; border-style: ridge; border-width: thin">
                                                                <asp:CheckBox ID="chkIntellisense" runat="server" Text="Intellisense:" Checked="true"
                                                                    OnCheckedChanged="chkIntellisense_CheckedChanged" AutoPostBack="true" />
                                                                <asp:CheckBox ID="chkKeywords" runat="server" Text="T-SQL & ODBC" Checked="true"
                                                                    OnCheckedChanged="chkKeywords_CheckedChanged" AutoPostBack="true" />
                                                                <asp:CheckBox ID="chkTableNames" runat="server" Text="Tables" Checked="true" OnCheckedChanged="chkTableNames_CheckedChanged"
                                                                    AutoPostBack="true" />
                                                                <asp:CheckBox ID="chkColumnNames" runat="server" Text="Columns" Checked="false" OnCheckedChanged="chkColumnNames_CheckedChanged"
                                                                    AutoPostBack="true" />
                                                            </div>
                                                        </ContentTemplate>
                                                    </asp:UpdatePanel>
                                                    &nbsp; &nbsp;
                                                    <br />
                                                    <div style="text-align: center">
                                                        <asp:TextBox runat="server" TextMode="MultiLine" ID="QueryTextbox" Width="350" Height="200" />
                                                        <ajaxToolKit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" ID="autoComplete1"
                                                            TargetControlID="QueryTextbox" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList"
                                                            MinimumPrefixLength="1" CompletionInterval="100" EnableCaching="false" CompletionSetCount="20"
                                                            CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem"
                                                            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :.">
                                                            <Animations>
                    <OnShow>
                        <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction Opacity="0" />
                            <HideAction Visible="true" />
                            
                            <%--Cache the original size of the completion list the first time
                                the animation is played and then set it to zero --%>
                            <ScriptAction Script="
                                // Cache the size and setup the initial size
                                var behavior = $find('AutoCompleteEx');
                                if (!behavior._height) {
                                    var target = behavior.get_completionList();
                                    behavior._height = target.offsetHeight - 2;
                                    target.style.height = '0px';
                                }" />
                            
                            <%-- Expand from 0px to the appropriate size while fading in --%>
                            <Parallel Duration=".4">
                                <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                            </Parallel>
                        </Sequence>
                    </OnShow>
                    <OnHide>
                        <%-- Collapse down to 0px and fade out --%>
                        <Parallel Duration=".4">
                            <FadeOut />
                            <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                        </Parallel>
                    </OnHide>
                                                            </Animations>
                                                        </ajaxToolKit:AutoCompleteExtender>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="databaseListItem">
                                                    <asp:CheckBox runat="server" ID="WrapCheckBox" Checked="True" Text="Wrap cell contents in results">
                                                    </asp:CheckBox>
                                                </td>
                                                <td class="databaseListItem" align="right">
                                                    <asp:Button runat="server" Text="Execute" CssClass="button" onMouseOver="this.style.color='#808080';"
                                                        onMouseOut="this.style.color='#000000';" ID="ExecuteButton" OnClick="ExecuteButton_Click">
                                                    </asp:Button>
                                                    <asp:Button runat="server" Text="Save query..." CssClass="button" onMouseOver="this.style.color='#808080';"
                                                        onMouseOut="this.style.color='#000000';" ID="SaveButton" OnClick="SaveButton_Click">
                                                    </asp:Button>
                                                </td>
                                            </tr>
                                        </table>
                                        <br />
                                        <a href="storedprocedures.aspx?database=<%=HttpContext.Current.Request.QueryString["database"] %>">
                                            <img src="images/Sproc_Ico.gif" alt="View/Edit Stored Procedures" style="border: 0px" />
                                            Stored Procedures</a> <b>
                                                <br />
                                                <br />
                                                Load Query</b>
                                        <br />
                                        <br />
                                        <input id="FileUploadInput" type="file" runat="server" />
                                        <br />
                                        <br />
                                        <asp:Button runat="server" Text="Load query..." CssClass="button" onMouseOver="this.style.color='#808080';"
                                            onMouseOut="this.style.color='#000000';" ID="LoadButton" OnClick="LoadButton_Click">
                                        </asp:Button>
                                        <br />
                                        <br />
                                        <asp:Label ID="ErrorLabel" runat="server" Visible="False" ForeColor="red"></asp:Label>
                                    </td>
                                </tr>
                                <!-- Section END -->
                                <!-- Section Footer START -->
                            </table>
                            <br />
                            <!-- Page content END -->
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr>
                                <td class="databaseListHeader">
                                    <asp:CheckBox ID="NamesCheckBox1" runat="server" AutoPostBack="true" Checked="true"
                                        OnCheckedChanged="NamesCheckBox1_CheckedChanged" />
                                    <asp:Label ID="NamesLabel1" runat="server" Text="Show Names in Database:"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <!--BEGIN ONE LINE-->
                                <td height="3" valign="middle" style="background-image: url(images/blue_dotted_line.gif);">
                                    <img src="images/blue_dotted_line.gif" width="50" height="3" alt="" border="0" /></td>
                                <!--END ONE LINE-->
                            </tr>
                            <tr>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                <asp:ListBox ID="NamesListBox" runat="server" AutoPostBack="true" Width="150" Height="400"
                                                    OnSelectedIndexChanged="NamesListBox_SelectedIndexChanged"></asp:ListBox>&nbsp;<br />
                                            </td>
                                            <td>
                                                <asp:ListBox ID="ColumnsListBox" runat="server" AutoPostBack="true" Width="150" Height="400" Visible="false" OnSelectedIndexChanged="ColumnsListBox_SelectedIndexChanged">
                                                </asp:ListBox>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>
                <asp:Panel runat="server" ID="ResultsPanel">
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>
